//引入集合模型
require("../models/knowledgePointsModel"); require("../models/questionsModel");
require("../models/usersModel");
const { collectionsModel } = require("../models/collectionsModel");

async function getAllCollections(req, res, next) {
    //    let user_id ="610a2fd8d8e4580eccb51123";
    let { user_id } = req.body;
    let allCollectionsArr = await collectionsModel.find({ user_id }).populate('questions_id').populate('user_id');
    res.send({ code: 1, allCollectionsArr });
}

async function delCollection(req, res, next) {

    const { user_id, questions_id } = req.body;
    let count = await collectionsModel.deleteMany({ questions_id, user_id });
    if (count.deletedCount > 0) {
        res.send({ code: 1, message: "取消收藏成功" });
    } else {
        res.send({ code: 0, message: "取消收藏失败" });
    }

}





module.exports = {
    //导出的函数名
    getAllCollections, delCollection
}